package com.enjoyor.soa.traffic.rest.tsms.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.tsms.SchemeInfoDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.ISchemeInfoConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

@Auth
@RestController
@RequestMapping({ "/scheme" }) // getCommonPlacePage
@Api("SchemeInfoController相关api")
@CrossOrigin
public class SchemeInfoController {

	@Autowired
	ISchemeInfoConsumeService iSchemeInfoConsumeService;

	/**
	 * 方案管理-分页
	 * @param page 分页参数
	 * @return
	 */
	@SuppressWarnings({ "rawtypes" })
	@GetMapping(value = { "/getSchemeInfoPage" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation(value = "方案管理分页", notes = "方案管理分页")
	@ApiImplicitParams({ 
			@ApiImplicitParam(name = "schemeId", value = "方案编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "schemeName", value = "方案名称", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "schemeBeginDate", value = "方案开始时间", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "schemeEndDate", value = "方案结束时间", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "schemeRankId", value = "方案等级编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "schemeStatusId", value = "方案状态编号", paramType = "query", dataType = "String") })
	public ResultPojo getSchemeInfoPage(
			@RequestParam(defaultValue = "",value="schemeId",required=false) String schemeId,
			@RequestParam(defaultValue = "",value="schemeName",required=false) String schemeName, 
			@RequestParam(defaultValue = "",value="schemeBeginDate",required=false) String schemeBeginDate,
			@RequestParam(defaultValue = "",value="schemeEndDate",required=false) String schemeEndDate, 
			@RequestParam(defaultValue = "",value="schemeRankId",required=false) String schemeRankId,
			@RequestParam(defaultValue = "",value="schemeStatusId",required=false) String schemeStatusId, 
			Page page, HttpServletRequest request) {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo = iSchemeInfoConsumeService.getSchemeInfoPage(page,schemeId,schemeName,schemeBeginDate,schemeEndDate,schemeRankId,schemeStatusId);
		return resultPojo;
	}
	
	/**
	 * 方案信息-list
	 * 
	 * @return
	 */
	@GetMapping(value = { "/getSchemeInfoList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = SchemeInfoDto.class, code = 0, message = "")
	@ApiOperation("方案信息List")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "schemeId", value = "方案编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "schemeName", value = "方案名称", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "schemeBeginDate", value = "方案开始时间", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "schemeEndDate", value = "方案结束时间", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "schemeRankId", value = "方案等级编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "schemeStatusId", value = "方案状态编号", paramType = "query", dataType = "String") })
	public ResultPojo getSchemeInfoList(
			@RequestParam(defaultValue = "",value="schemeId",required=false) String schemeId,
			@RequestParam(defaultValue = "",value="schemeName",required=false) String schemeName, 
			@RequestParam(defaultValue = "",value="schemeBeginDate",required=false) String schemeBeginDate,
			@RequestParam(defaultValue = "",value="schemeEndDate",required=false) String schemeEndDate, 
			@RequestParam(defaultValue = "",value="schemeRankId",required=false) String schemeRankId,
			@RequestParam(defaultValue = "",value="schemeStatusId",required=false) String schemeStatusId,
			HttpServletRequest request) {
		Boolean isFull = false; 
		return iSchemeInfoConsumeService.getSchemeInfoList(schemeId, schemeName, schemeBeginDate, schemeEndDate,
				schemeRankId, schemeStatusId, isFull);
	}
	/**
	 * 方案详细信息-list
	 * 
	 * @return
	 */
	@GetMapping(value = { "/getSchemeBaseInfoList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = SchemeInfoDto.class, code = 0, message = "")
	@ApiOperation("方案信息List集合（包含附件、审核以及任务信息）")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "schemeId", value = "方案编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "schemeName", value = "方案名称", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "schemeBeginDate", value = "方案开始时间", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "schemeEndDate", value = "方案结束时间", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "schemeRankId", value = "方案等级编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "schemeStatusId", value = "方案状态编号", paramType = "query", dataType = "String") })
	public ResultPojo getSchemeBaseInfoList(
			@RequestParam(defaultValue = "",value="schemeId",required=false) String schemeId,
			@RequestParam(defaultValue = "",value="schemeName",required=false) String schemeName, 
			@RequestParam(defaultValue = "",value="schemeBeginDate",required=false) String schemeBeginDate,
			@RequestParam(defaultValue = "",value="schemeEndDate",required=false) String schemeEndDate, 
			@RequestParam(defaultValue = "",value="schemeRankId",required=false) String schemeRankId,
			@RequestParam(defaultValue = "",value="schemeStatusId",required=false) String schemeStatusId,
			HttpServletRequest request) {
		Boolean isFull = true;
		return iSchemeInfoConsumeService.getSchemeInfoList(schemeId, schemeName, schemeBeginDate, schemeEndDate,
				schemeRankId, schemeStatusId, isFull);
	}

	@PostMapping(value = { "/addSchemeInfo" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("添加方案信息")
	public ResultPojo addSchemeInfo(@RequestBody SchemeInfoDto schemeInfoDto, HttpServletRequest request) {
		return iSchemeInfoConsumeService.insertSchemeInfo(schemeInfoDto,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}

	@PutMapping(value = { "/editSchemeInfo" }, consumes = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("修改方案信息")
	public ResultPojo editSchemeInfo(@RequestBody SchemeInfoDto schemeInfoDto, HttpServletRequest request) {
		return iSchemeInfoConsumeService.updateSchemeInfo(schemeInfoDto,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}

	@DeleteMapping(value = { "/deleteSchemeInfo" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("删除方案信息")
	@ApiImplicitParam(name = "schemeId", value = "方案编号", paramType = "query", required = true, dataType = "String")
	public ResultPojo deleteSchemeInfo(
			@RequestParam(defaultValue = "",value="schemeId", required=true) String schemeId, 
			HttpServletRequest request) {
		return iSchemeInfoConsumeService.deleteSchemeInfoById(schemeId,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	@PutMapping(value = { "/submitSchemeInfo" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("提交方案信息")
	@ApiImplicitParam(name = "schemeId", value = "方案编号", paramType = "query", required = true, dataType = "String")
	public ResultPojo submitSchemeInfo(
			@RequestParam(defaultValue = "") String schemeId, 
			HttpServletRequest request) {
		return iSchemeInfoConsumeService.commitSchemeInfo(schemeId,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	

	@PutMapping(value = { "/checkSchemeInfo" }, produces = {"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("审核方案信息")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "schemeId", value = "方案编号", paramType = "query", required = true, dataType = "String"),
		@ApiImplicitParam(name = "schemeStatusId", value = "审核状态编号", paramType = "query", required = true, dataType = "String"),
		@ApiImplicitParam(name = "checkIdea", value = "审核说明", paramType = "query", dataType = "String")})
	public ResultPojo checkSchemeInfo(
			@RequestParam(defaultValue = "") String schemeId,
			@RequestParam(defaultValue = "") String schemeStatusId, 
			@RequestParam(defaultValue = "") String checkIdea, HttpServletRequest request) {
		return iSchemeInfoConsumeService.auditSchemeInfo(schemeId, schemeStatusId, checkIdea, 
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 方案管理-获取待执行方案List
	 * @return
	 */
	@GetMapping(value = { "/getSchemeForWeek" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("获取待执行方案List")
	//@ApiImplicitParam(name="timelist", value="时间数组", required=true, paramType="query" ,allowMultiple=true, dataType = "String")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "schemeId", value = "方案编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "schemeBeginDate", value = "开始日期", paramType = "query", required = true, dataType = "String"),
		@ApiImplicitParam(name = "schemeEndDate", value = "结束日期", paramType = "query", required = true, dataType = "String"),
		@ApiImplicitParam(name = "executeStatusId", value = "任务状态编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "driverPoliceId", value = "驾驶员编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "beforeLicensePlate", value = "前导车牌", paramType = "query", dataType = "String")})
	public ResultPojo getSchemeForWeek(
			//@RequestParam String timelist,
			@RequestParam(defaultValue = "", value="schemeId", required=false) String schemeId,
			@RequestParam(defaultValue = "", value="schemeBeginDate", required=true) String schemeBeginDate, 
			@RequestParam(defaultValue = "", value="schemeEndDate", required=true) String schemeEndDate, 
			@RequestParam(defaultValue = "", value="executeStatusId", required=false) String executeStatusId, 
			@RequestParam(defaultValue = "", value="driverPoliceId", required=false) String driverPoliceId,  
			@RequestParam(defaultValue = "", value="beforeLicensePlate", required=false) String beforeLicensePlate, 
			HttpServletRequest request) {
		//fastJson将传入的时间数据转换成List；
		//List list = JSONArray.parseArray(timelist, String.class);
		return iSchemeInfoConsumeService.getSchemeForWeek(schemeId, schemeBeginDate, schemeEndDate, executeStatusId, 
				driverPoliceId, beforeLicensePlate); 
	}
	
	/**
	 * 修改方案待执行状态
	 * @return
	 */
	@PutMapping(value = { "/editSchemeWaitStatus" }, produces = {"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("修改方案待执行状态")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", required = true, dataType = "String"),
		@ApiImplicitParam(name = "isWaitExecute", value = "待执行状态(是为1，否为0)", paramType = "query", required = true, dataType = "String")})
	public ResultPojo editSchemeWaitStatus(
			@RequestParam(defaultValue = "", value="executeTaskId", required=true) String executeTaskId, 
			@RequestParam(defaultValue = "", value="isWaitExecute", required=true) String isWaitExecute, 
			HttpServletRequest request) {
		return iSchemeInfoConsumeService.editSchemeWaitStatus(executeTaskId, isWaitExecute, 
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 方案管理-（预演） 查询规定时间范围的方案信息；
	 * 
	 * @return
	 */
	@GetMapping(value = { "/getPreviewSchemeList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("（预演） 查询规定时间范围的方案信息")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "schemeBeginDate", value = "开始日期", paramType = "query", required = true, dataType = "String"),
		@ApiImplicitParam(name = "schemeEndDate", value = "结束日期", paramType = "query", required = true, dataType = "String")})
	public ResultPojo getPreviewSchemeList(
			@RequestParam(defaultValue = "", value="schemeBeginDate", required=true) String schemeBeginDate, 
			@RequestParam(defaultValue = "", value="schemeEndDate", required=true) String schemeEndDate, 
			HttpServletRequest request) {
		//fastJson将传入的时间数据转换成List；
		//List list = JSONArray.parseArray(timelist, String.class);
		ResultPojo resultPojo = new ResultPojo();
		resultPojo = iSchemeInfoConsumeService.getPreviewSchemeList(schemeBeginDate, schemeEndDate);
		return resultPojo;
	}
	/**
	 * 执行任务数量统计 
	 * @return
	 */
	@GetMapping(value = { "/getExecuteStatusCollect" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("执行任务数量统计 ")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "taskId", value = "任务编号", paramType = "query", required = false, dataType = "String"),
		@ApiImplicitParam(name = "schemeId", value = "方案编号", paramType = "query", required = false, dataType = "String"),
		@ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", required = false, dataType = "String"),
		@ApiImplicitParam(name = "executeDate", value = "执行日期", paramType = "query", required = false, dataType = "String")})
	public ResultPojo getExecuteStatusCollect(
			@RequestParam(defaultValue = "", value="taskId", required=false) String taskId, 
			@RequestParam(defaultValue = "", value="schemeId", required=false) String schemeId, 
			@RequestParam(defaultValue = "", value="executeTaskId", required=false) String executeTaskId, 
			@RequestParam(defaultValue = "", value="executeDate", required=false) String executeDate, 
			HttpServletRequest request) {
		return iSchemeInfoConsumeService.getExecuteStatusCollect(taskId, schemeId, executeTaskId, executeDate);
	}
	/**
	 * 实际执行开始时间查询 
	 * @return
	 */
	@GetMapping(value = { "/getRealExecuteTime" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("实际执行开始时间查询")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "taskId", value = "任务编号", paramType = "query", required = false, dataType = "String"),
		@ApiImplicitParam(name = "schemeId", value = "方案编号", paramType = "query", required = false, dataType = "String"),
		@ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", required = false, dataType = "String"),
		@ApiImplicitParam(name = "executeDate", value = "执行日期", paramType = "query", required = false, dataType = "String")})
	public ResultPojo getRealExecuteTime(
			@RequestParam(defaultValue = "", value="taskId", required=false) String taskId, 
			@RequestParam(defaultValue = "", value="schemeId", required=false) String schemeId, 
			@RequestParam(defaultValue = "", value="executeTaskId", required=false) String executeTaskId, 
			@RequestParam(defaultValue = "", value="executeDate", required=false) String executeDate, 
			HttpServletRequest request) {
		return iSchemeInfoConsumeService.getRealExecuteTime(taskId, schemeId, executeTaskId, executeDate);
	}
}
